#include "tim3.h"
#include "ymodem.h"
Buffer buf = {{0}, 0};
static void RCC_Config(void) {
	 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
}

static void TIM3_Cofnig(void) {
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;
	TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
	TIM_TimeBaseStruct.TIM_Period = 9999;
	TIM_TimeBaseStruct.TIM_Prescaler = 71;
	TIM_TimeBaseStruct.TIM_ClockDivision = 0;
	TIM_TimeBaseStruct.TIM_CounterMode=TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStruct);
	TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
	TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
}
 
static void NVIC_Config(void) {
	NVIC_InitTypeDef NVIC_InitStructure; 
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); 
	NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; 
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; 
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
	NVIC_Init(&NVIC_InitStructure);
}

void TIM3_Init(void) {
	RCC_Config();
	NVIC_Config();
	TIM_Cmd(TIM3, DISABLE);	
	TIM3_Cofnig();
}

